package edu.bw.mapper;

import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;
import po.User;

import java.util.List;

public interface UserMapper {
    /**
     * 根据用户的id查询用户信息
     *
     * @param id
     * @return
     */
    @Select("SELECT id,username,birthday,gender,address FROM mybatis02.`user` WHERE id = #{id} ")
    User findById(int id);

    /**
     * 查询所有用户,使用延迟加载
     * @return
     */
    @Results({
            @Result(column = "id",property = "id",id = true),
            @Result(column = "id",property = "orders",javaType = List.class,
                    many = @Many(select = "edu.bw.mapper.OrderMapper.findOrdersByUserId",fetchType = FetchType.LAZY))

    })
    @Select("SELECT id,username,birthday,gender,address FROM mybatis02.`user`")
    List<User> findAllLazy();
}
